package com.test.test2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Mapper2 extends Mapper<LongWritable, Text, LongWritable, Text> {
    final LongWritable k = new LongWritable();
    final Text v = new Text();
    // 按原有顺序输出
    long num = 0;
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, LongWritable, Text>.Context context) throws IOException, InterruptedException {

        if (key.get() == 0){
            num++;
            return;
        }
        String line = value.toString();
        String[] split = line.split(",");
        // 获取日期
        String date = split[0];
        // 获取收盘价
        String close = split[4];
        if ("null".equals(close)){
            return;
        }
        k.set(num++);
        v.set(date + "," + close);
        context.write(k, v);
    }
}
